home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 113 / gfatip02 / gfatip02.txt < prev   
Text File  |  1987-11-28  |  5KB  |  120 lines

  1.                                                        May 25 1987
  2.  
  3. GFATIP02.DOC        Constructing a System Drive Map
  4.  
  5.                         By John B. Holder
  6.         Senior Software Engineer, Marathon Computer Press
  7.  
  8.  
  9.      This is the second in a planned series of tips on how to get 
  10. the most out of your GFA Basic Interpreter/Compiler.  The topic is 
  11. Mapping your System.  What this means in plain english is: 
  12. "Determining how many logical drives are connected to the system".
  13. Why do we need to know that you may ask?  Unless you will never  
  14. write programs for anyone besides yourself, this will be a good 
  15. technique to learn for reasons described below.
  16.  
  17.      What will this do?  Well, it will give you a binary 
  18. presentation of your system's drive status.  Imagine each drive 
  19. hooked up to the system as a single digit.  By this I mean that if 
  20. you have 3 drives attached to the machine the drive map will be 
  21. represented by the symbols 111.  If there were 10 drives connected 
  22. to the system the drive map would be 1111111111.  Starting to make 
  23. sense?
  24.      Now it gets a little complicated.  So you say, Wow! that's 
  25. great; all we have to do now is call the Drive_map procedure and 
  26. get Len(Num$) to find out which drives are attached.  Not 
  27. completely true.  If the user has 4 drives attached and they are 
  28. in the sequence of A B C D then you could do that.  But the first 
  29. problem comes into play when you consider that the BIOS always 
  30. returns a value of  11  for drives attached.  That's so you can 
  31. make those handy dandy full disk backups by dragging Icon A to 
  32. Icon B and sit back while it copies all of the files for you.  So 
  33. if it always returns a signal that says that Drive B is connected 
  34. whether or not it really is, how do you get around it?  Well, the 
  35. answer is you don't.  The operating system handles this condition 
  36. by telling the user to insert disk B into Drive A and vice versa 
  37. to get around it.  So not all's bad with this condition.
  38.      Ok, so we can now accept the fact that we'll always get a 
  39. return of at least  11  no matter what.  Now how do we tell if 
  40. another drive is missing or out of order?  At this point we must 
  41. go back to the above analogy of 1 digit per drive.
  42.  
  43.                 Take the following configuration:
  44.  
  45.                     A    B    C    D    _    F
  46.  
  47.      The underscore is represented above to show that the user has 
  48. somehow managed to install a Ram Drive or something in Drive F's 
  49. slot, thus bypassing drive E.  Now if you call the Drive_map 
  50. procedure and use:
  51.  
  52.                          Print Len(Num$)
  53.  
  54.      You'll see a  6  appear on the screen, but we know right off 
  55. that it's not right {because we cheated and saw which drives were 
  56. connected, after all we own the machine right?}.  But if you use:
  57.  
  58.                             Print Num$
  59.  
  60.      You will now see the system as it really exists.  The 
  61. following will appear on the screen
  62.  
  63.                               101111
  64.  
  65.      Pretty handy if you don't want your latest and greatest 
  66. program to hopelessly crash because Joe BetaTester had a Ram Drive 
  67. out of Normal Sequence.  Now getting an actual picture of the 
  68. system is as simple as:
  69.  
  70. @Drive_map   ! Gosub Drive_map
  71. For X =0 To Len(Num$)-1 step 1
  72.      If Mid$(Num$,Len(Num$)-X,1)="1"
  73.        Print "Drive ";Chr$(Asc("A")+X);" Is Online"
  74.      Else
  75.        Print "Drive ";Chr$(Asc("A")+X);" Not Connected!"
  76.      Endif
  77. Next X
  78.  
  79.      I hope this little routine and explanation of how it works 
  80. will assist you in getting the most out of your investment in a 
  81. wonderful Interpreter and Compiler.  Comments are welcome, good or 
  82. bad.  I've included the sample source code in a Basic .BAS file 
  83. in the archive for you to run as is.  Have fun!
  84.  
  85.  
  86.                          John B. Holder
  87.  
  88.                             GRIFJOHN
  89.  
  90.  
  91. Here's the actual procedure and some commented source code:
  92.  
  93.  
  94. ' Drive_map Returns two values for you; they are:
  95. ' Num% = a bit vector containing active drives
  96. ' Num$ = a binary representation of connected drives
  97. ' If you had drives A,B,C connected num%=7 and num$=111
  98. ' In this way you can count up the active drives from A-P by
  99. ' looking at the resulting bit vector representation.
  100. ' If drives are not in order there may be zeros in between
  101. ' numbers.  Example:  You have drive A & B, plus a Ram Drive M
  102. '                      M__________BA
  103. ' drive map =          1000000000011
  104. '
  105. ' Or the more classical situation:
  106. '                                CBA
  107. ' drive map =                    111
  108. '
  109. '
  110. ' Example:
  111. @Drive_map
  112. Print Num%
  113. Print Num$
  114. '
  115. '
  116. Procedure Drive_map
  117.   Num%=Bios(10)
  118.   Num$=Bin$(Num%)
  119. Return
  120.